package edu.qd.learn.newchapter.chapter03.patter;

import edu.qd.learn.newchapter.chapter03.reflect.Farmer;

/**
 * Bean类 javaBean （java 豆子）
 *
 * @author 布衣
 */
public class BeanFactory {

    /**
     * 根据beanName获取bean对象
     *
     * @param beanName 名称
     * @return
     */
    public static Object getBean(String beanName) {
        try {
            return Class.forName(beanName).newInstance();
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        Farmer o = (Farmer)BeanFactory.getBean("edu.qd.learn.newchapter.chapter03.reflect.Farmer");
        o.setName("tttt");

        System.out.println(o.getName());
    }

}
